package com.dbf.site.client.main.view;

import java.util.Date;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.view.ReverseViewInterface;
import com.sencha.gxt.core.client.resources.ThemeStyles;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.NorthSouthContainer;
import com.sencha.gxt.widget.core.client.info.Info;
import com.sencha.gxt.widget.core.client.menu.CheckMenuItem;
import com.sencha.gxt.widget.core.client.menu.DateMenu;
import com.sencha.gxt.widget.core.client.menu.HeaderMenuItem;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuBar;
import com.sencha.gxt.widget.core.client.menu.MenuBarItem;
import com.sencha.gxt.widget.core.client.menu.MenuItem;

public class WelcomeView implements IWelcomeView, ReverseViewInterface<IWelcomeView.IWelcomePresenter>{
	
	private IWelcomeView.IWelcomePresenter presenter;
	private FramedPanel container;
	
	public WelcomeView(){
		this.createView();
	}
	private void createView(){
		container = new FramedPanel();
	    container.setHeight("100%");
	    container.setHeaderVisible(false);
	    container.setBodyStyle("background-color:#3892d3;");
        SelectionHandler<Item> handler = new SelectionHandler<Item>() {
          @Override
          public void onSelection(SelectionEvent<Item> event) {
            if (event.getSelectedItem() instanceof MenuItem) {
              MenuItem item = (MenuItem) event.getSelectedItem();
              Info.display("Action", "You selected the " + item.getText());
            }
          }
        };
   
        Menu subMenuItem2 = new Menu();
        subMenuItem2.addSelectionHandler(handler);
        subMenuItem2.add(new MenuItem("readme.txt"));
        subMenuItem2.add(new MenuItem("helloworld.txt"));
   
        MenuItem subMenuNew = new MenuItem("New");
        MenuItem subMenuFile = new MenuItem("Open File");
        subMenuFile.setSubMenu(subMenuItem2);
   
        Menu menuFile = new Menu();
        menuFile.addSelectionHandler(handler);
        menuFile.add(subMenuNew);
        menuFile.add(subMenuFile);
   
        Menu subMenuEdit = new Menu();
        subMenuEdit.addSelectionHandler(handler);
        subMenuEdit.add(new MenuItem("Cut"));
        subMenuEdit.add(new MenuItem("Copy"));
   
        MenuBarItem menuBarEdit = new MenuBarItem("Edit", subMenuEdit);
   
        Menu subMenuItem3 = new Menu();
        subMenuItem3.addSelectionHandler(handler);
        subMenuItem3.add(new MenuItem("Search"));
        subMenuItem3.add(new MenuItem("File"));
        subMenuItem3.add(new MenuItem("Java"));
   
        MenuBarItem menuBarItem3 = new MenuBarItem("Search", subMenuItem3);
   
        CheckMenuItem checkMenuItem1 = new CheckMenuItem("I Like Cats");
        checkMenuItem1.setChecked(true);
   
        CheckMenuItem menuItemBlue = new CheckMenuItem("Blue Theme");
        CheckMenuItem menuItemGray = new CheckMenuItem("Gray Theme");
        CheckMenuItem menuItemNeptune = new CheckMenuItem("Neptune Theme");
   
        menuItemBlue.setChecked(true);
        menuItemBlue.setGroup("radios");
        menuItemGray.setGroup("radios");
        menuItemNeptune.setGroup("radios");
   
        Menu radioMenu = new Menu();
        radioMenu.addSelectionHandler(handler);
        radioMenu.add(new HeaderMenuItem("Built-in GXT Themes"));
        radioMenu.add(menuItemBlue);
        radioMenu.add(menuItemGray);
        radioMenu.add(menuItemNeptune);
   
        MenuItem menuItemRadios = new MenuItem("Radio Options");
        menuItemRadios.setSubMenu(radioMenu);
   
        final DateMenu subdateMenu = new DateMenu();
        subdateMenu.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
          @Override
          public void onValueChange(ValueChangeEvent<Date> event) {
            Date d = event.getValue();
            DateTimeFormat f = DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT);
            Info.display("Value Changed", "You selected " + f.format(d));
            subdateMenu.hide(true);
          }
        });
   
   
   
        MenuBar menuBar = new MenuBar();
        menuBar.addStyleName(ThemeStyles.get().style().borderTop());
        menuBar.addStyleName(ThemeStyles.get().backgroundColorLight());
        menuBar.add(new MenuBarItem("Home", menuFile));
        menuBar.add(menuBarEdit);
        menuBar.add(menuBarItem3);
   
        NorthSouthContainer northSouthContainer = new NorthSouthContainer();
        northSouthContainer.setNorthWidget(menuBar);
   
        container.add(northSouthContainer);
	    
	    
	}
	@Override
	public Widget asWidget() {
		return container;
	}

	@Override
	public void setPresenter(IWelcomePresenter presenter) {
		this.presenter = presenter;		
	}

	@Override
	public IWelcomePresenter getPresenter() {
		return this.presenter;
	}

}
